//package com.xingongchang.baolebei.protocol;
//
//import org.json.JSONException;
//import org.json.JSONObject;
//import com.external.activeandroid.Model;
//import com.external.activeandroid.annotation.Column;
//import com.external.activeandroid.annotation.Table;
//
//@Table(name = "TOPIC")
//public class TOPIC extends Model {
//
//	@Column(name = "isanonymous")
//	public int isanonymous;
//
//	@Column(name = "userid", unique = true)
//	public int userid;
//
//	@Column(name = "title")
//	public String title;
//
//	@Column(name = "body")
//	public String body;
//
//	@Column(name = "replycount")
//	public String replycount;
//
//	@Column(name = "creaton")
//	public String creaton;
//
//	@Column(name = "is_img")
//	public int is_img;
//
//	@Column(name = "username")
//	public String username;
//
//	@Column(name = "imgurl")
//	public String imgurl;
//
//	@Column(name = "is_top")
//	public int is_top;
//
//	@Column(name = "topicid")
//	public int topicid;
//
//	@Column(name = "classid")
//	public int classid;
//
//	public static TOPIC fromJson(JSONObject jsonObject) throws JSONException {
//		if (null == jsonObject) {
//			return null;
//		}
//
//		TOPIC localItem = new TOPIC();
//
//		localItem.isanonymous = jsonObject.optInt("isanonymous");
//		localItem.userid = jsonObject.optInt("userid");
//		localItem.title = jsonObject.optString("title");
//		localItem.body = jsonObject.optString("body");
//		localItem.replycount = jsonObject.optString("replycount");
//		localItem.creaton = jsonObject.optString("creaton");
//		localItem.is_img = jsonObject.optInt("is_img");
//		localItem.imgurl = jsonObject.optString("imgurl");
//		localItem.is_top = jsonObject.optInt("is_top");
//		localItem.topicid = jsonObject.optInt("topicid");
//		localItem.classid = jsonObject.optInt("classid");
//		localItem.username = jsonObject.optString("username");
//
//		return localItem;
//	}
//
//}



package com.xingongchang.baolebei.protocol;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.external.activeandroid.Model;
import com.external.activeandroid.annotation.Column;
import com.external.activeandroid.annotation.Table;

@Table(name = "TOPIC")
public class TOPIC extends Model {

	@Column(name = "is_top")
	public int is_top;

	@Column(name = "showImg")
	public String showImg;
	
	@Column(name = "replycount")
	public String replycount;

	@Column(name = "creaton")
	public String creaton;
	
	@Column(name = "userid", unique = true)
	public int userid;
	
	public String[] imgurl;
	
	@Column(name = "title")
	public String title;

	@Column(name = "body")
	public String body;

	@Column(name = "user_name")
	public String user_name;
	
	@Column(name = "topicid")
	public int topicid;

	@Column(name = "classid")
	public int classid;

	public static TOPIC fromJson(JSONObject jsonObject) throws JSONException {
		if (null == jsonObject) {
			return null;
		}
		JSONArray subItemArray;
		TOPIC localItem = new TOPIC();

		localItem.userid = jsonObject.optInt("userid");
		localItem.title = jsonObject.optString("title");
		localItem.body = jsonObject.optString("body");
		localItem.replycount = jsonObject.optString("replycount");
		localItem.creaton = jsonObject.optString("creaton");


		subItemArray = jsonObject.optJSONArray("imgurl");
		if (null != subItemArray) {
			localItem.imgurl = new String[subItemArray.length()];
			for (int i = 0; i < subItemArray.length(); i++) {
				JSONObject subItem = subItemArray.getJSONObject(i);
				localItem.imgurl[i] = subItem.optString("filepath");
			}
		}
		
		localItem.showImg = jsonObject.optString("showImg");
		localItem.is_top = jsonObject.optInt("is_top");
		localItem.topicid = jsonObject.optInt("topicid");
		localItem.classid = jsonObject.optInt("classid");
		localItem.user_name = jsonObject.optString("user_name");

		return localItem;
	}

}